package com.zff.wechat.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.zff.web.constants.Constants;
import com.zff.wechat.menu.Button;
import com.zff.wechat.menu.CommonButton;
import com.zff.wechat.menu.ComplexButton;
import com.zff.wechat.menu.Menu;
import com.zff.wechat.menu.ViewButton;
import com.zff.wechat.po.AccessToken;
import com.zff.wechat.util.GDUtil;

public class MenuManager {

	private static final Log LOG = LogFactory.getLog(MenuManager.class);
	
	public static void main(String[] args) {
		 // 第三方用户唯一凭证
        String appId = "wx364d823b27f56cd8";
        // 第三方用户唯一凭证密钥
        String appSecret = "43261e9ca28956683aab7a2ac09af077";

        // 调用接口获取access_token
        AccessToken at = GDUtil.getAccessToken(appId, appSecret);

        if (null != at) {
            // 调用接口创建菜单
            int result = GDUtil.createMenu(getMenu(), at.getToken());

            // 判断菜单创建结果
            if (Constants.zero == result)
            	LOG.info("菜单创建成功！");
            else
            	LOG.info("菜单创建失败，错误码：" + result);
        }
	}
	
	private static Menu getMenu() {
        CommonButton btn11 = new CommonButton();
        btn11.setName("别点，会爆炸");
        btn11.setType("click");
        btn11.setKey("11");

        CommonButton btn12 = new CommonButton();
        btn12.setName("别点，真的会爆炸");
        btn12.setType("click");
        btn12.setKey("12");

        CommonButton btn13 = new CommonButton();
        btn13.setName("你别点，行不，好烦啊");
        btn13.setType("click");
        btn13.setKey("13");

        ViewButton vbt1 = new ViewButton();
		vbt1.setUrl("http://guyunyixiao.sxl.cn/");
		vbt1.setName("鼓韵艺校");
		vbt1.setType("view");
		
		ViewButton vbt2 = new ViewButton();
		vbt2.setUrl("http://www.dancoder.cn/wechat/index.html");
		vbt2.setName("用户登录");
		vbt2.setType("view");
		
		ViewButton vbt3 = new ViewButton();
		vbt3.setUrl("http://goudan.tunnel.qydev.com/wechat/wechat/face_age.html");
		vbt3.setName("人脸年龄识别");
		vbt3.setType("view");

        CommonButton btn31 = new CommonButton();
        btn31.setName("路径规划");
        btn31.setType("click");
        btn31.setKey("pathplanning");

        CommonButton btn32 = new CommonButton();
        btn32.setName("我的位置");
        btn32.setType("click");
        btn32.setKey("mylocation");
        
        CommonButton btn33 = new CommonButton();
        btn33.setName("人脸识别");
        btn33.setType("click");
        btn33.setKey("facerecognition");
        
        /**
         * 微信：  mainBtn1,mainBtn2,mainBtn3底部的三个一级菜单。
         */
        
        ComplexButton mainBtn1 = new ComplexButton();
        mainBtn1.setName("生活助手");
        mainBtn1.setSub_button(new CommonButton[] { btn11, btn12, btn13});

        
        ComplexButton mainBtn3 = new ComplexButton();
        mainBtn3.setName("更多体验");
        mainBtn3.setSub_button(new CommonButton[] { btn31, btn32 ,btn33});
        
        ComplexButton mainBtn4 = new ComplexButton();
        mainBtn4.setName("用户中心");
        mainBtn4.setSub_button(new ViewButton[] {vbt1,vbt2,vbt3});

        
        /**
         * 封装整个菜单
         */
        Menu menu = new Menu();
        menu.setButton(new Button[] { mainBtn1, mainBtn4, mainBtn3 });

        return menu;
    }
}
